<!-- 核销订单 -->
<template>
    <div class="page-box h100 display-flex czbj">
        <p class="title-label mb10">{{ jdsfdfs }}--订单管理</p>
        <div>

            <div class="display-flex">
                <div class="zxczxertert">
                    <n-input v-model:value="jnxsdfd.deductionOrderId" type="text" placeholder="订购号" />
                </div>

                <div class="zxczxertert ml20">
                    <n-select v-model:value="jnxsdfd.deduction_status" placeholder="核销订单状态" :options="jcfdsfs" />
                </div>


                <div class="ml20">
                    <n-button type="info" @click="initsd" :loading="jxcfdfdf"> 搜索 </n-button>
                    <!-- <n-button type="info" @click="hf('addka')" class="ml20"> +添加 </n-button> -->
                </div>
            </div>

        </div>
        <n-data-table :border="true" class="mt20" :columns="columns" :data="shopInfos" :bordered="false" />

        <div class="mt20    display-flex">
            <div class="flex-1"></div>
            <div class="cdfvdfsxgrtr">
                <n-pagination v-model:page="jnxsdfd.page" :page-count="totalNum" @update:page='xzcsdertrt' />
            </div>
        </div>
        <!-- <div class="mt20 z9 fz12">
        
        新增或修改可能不会立即生效，需要等待10秒-5分钟同步  
      </div> -->
    </div>
</template>
<script lang='ts' setup>
import { ref, reactive, h } from 'vue'
import { dxget, hf, dialog, dxpost } from "../../util/index";
import { NTag, NButton } from 'naive-ui';
const shopInfos = ref([])
const jxcfdfdf = ref(false)
const mendianl = ref([])
const knmxfdf = ref(false)
const jdsfdfs = localStorage.sjmcsee
let jcfdsfs = [
    { label: "全部", value: "" },
    { label: "待支付", value: "UNPAID" },
    { label: "支付成功", value: "PAYMENT_SUCCESS" },
    { label: "支付失败", value: "PAYMENT_FAILED" },
    { label: "已退款", value: "REFUND" },

]
let jcfdsfsB = [
    { label: "核销扣款单", value: "USE_DEDUCTION" },
    { label: "追优惠扣款单", value: "DISCOUNT_DEDUCTION" },

]

const columns = ref(
    [
        { title: '订购号', key: 'deductionOrderId', width: 220, },
        { title: '订单编号', key: 'tradeNo', width: 220, },
        { title: '订购号', key: 'cardId', align: "center" },
        {
            title: '期数', key: 'period', align: "center",
            render(row) {
                return h('div', { class: 'dfsfsdrtrt' }, row.period)
            }
        },
        { title: '计划扣款时间', key: 'planDeductionTime', align: "center" },
        { title: '实际扣款时间', key: 'deductionTime', align: "center" },

        {
            title: '订单状态', key: 'deductionStatus', align: "center",
            render(row) {
                try{
                    return jcfdsfs.filter(a => a.value == row.deductionStatus)[0].label
                }catch(e){
                    
                }
            }

        },
        {
            title: '扣款金额', key: 'deductionAmount', align: "center", render(row) {
                if(row.deductionAmount){
                    return row.deductionAmount / 100
                }else{
                    return '--'
                }
            },
        },
        {
            title: '退款金额', key: 'refundCash', align: "center", render(row) {
                if(row.refundCash){
                    return row.refundCash / 100
                }else{
                    return '--'
                }
                
            },
        },

        { title: '扣款失败次数', key: 'deductionFailTimes', align: "center" },
        {
            title: '核销订单类型', key: 'deductionOrderType', align: "center", render(row) {
                return jcfdsfsB.filter(a => a.value == row.deductionOrderType)[0].label
            },
        },
        {
            title: '操作', align: "center", render(row) {
                return h(NButton, {
                    type: 'primary',
                    size: 'small',
                    quaternary: true,
                    onClick: () => {
                        hf('hexiaoxq', {
                            deduction_order_id: row.deductionOrderId,
                            cardId:row.cardId,
                            userId: row.userId,
                            openId: row.openId
                        })
                    }
                }, '查看详情')
            }
        }



    ]
)

const totalNum = ref()

const jnxsdfd = ref({
    card_id: "",//售卖订单id
    deduction_status: null,//核销订单状态
    page: 1
})
const zxcxzrtret = ref(false)
const zhjhsd = [

    { label: '已发布', value: 'PUBLISHED' },
    { label: '审核中', value: 'REVIEWING' },
    { label: '审核失败', value: 'REJECTED' },
    { label: '已下架', value: 'DELISTING' },
    { label: '已冻结', value: 'FREEZING' },
    { label: '已过期', value: 'EXPIRED' },

]
const jnxdfd = [
    { label: '统一收款', value: '1' },
    { label: '分店结算', value: '2' },
]
const jzxcsdfd = (valus) => {
    return zhjhsd.filter(a => a.value == valus)[0].label
}
const jzxcsdfdb = (valus) => {
    try {

        return jnxdfd.filter(a => a.value == valus)[0].label
    } catch (e) {

    }
}
const initsd = async () => {
    jxcfdfdf.value = true
    const { data } = await dxget('meirong/wantu/deductionorderbatchquery', jnxsdfd.value)
    jxcfdfdf.value = false
    shopInfos.value = data.content
    totalNum.value = data.totalNum
    // pagination.value.pageCount = data.totalSize
}
initsd()
const xzcsdertrt = (data) => {
    jnxsdfd.value.page = data
    initsd()
}
const shanchuser = async (data) => {
    const res = await dialog("确认删除吗？");
    if (res == 1) {
        //等于1为确认删除了
        const ret = await dxpost('meirong/wantu/sanchudp', { shopId: data.shopId })
        window.$message.success('删除成功！')
        initsd()
    }
}
const xiazai = async (sd, operateStatus) => {
    zxcxzrtret.value = true
    const { data } = await dxpost('meirong/wantu/xiugmodify', { cardTemplateId: sd.cardTemplateId, operateStatus })
    console.log(data);
    zxcxzrtret.value = false
    if (data.code != 10000) {
        window.$message.error(data.subMsg)
        return
    }


    initsd()
}
const mendianList = async () => {
    const { data } = await dxget("meirong/wantu/mendianList")

    console.log(data);
    mendianl.value = data
}
mendianList()
</script>
<style scoped>
.zxczxertert {
    width: 300px;
}
</style>